#include "init.h"
#include "test.h"
#include "ScnsInclude.h"

static uint8 nrfSendBuf[6*2+1];

void startCallBack(ScnsKeyMsg keyMsg)
{
    if(keyMsg.status==SCNS_KEY_PRESS_DOWN)
        nrfSendBuf[12]=115;
    else if(keyMsg.status==SCNS_KEY_PRESS_HOLD||keyMsg.status==SCNS_KEY_PRESS_HOLD_DOWN)
        nrfSendBuf[12]=114;
    else
        nrfSendBuf[12]=0;
}

int main(void)
{
    init();
    test();
    //scnsLedRgbSet(SCNS_LED_RGB_L,SCNS_COLOR_RGB888_RED);
    //scnsLedRgbSet(SCNS_LED_RGB_R,SCNS_COLOR_RGB888_GREEN);
    //scnsLedRgbSet(SCNS_LED_RGB_R,SCNS_COLOR_RGB888_RED);
    static const ScnsColorRgb888 colors[]={
        SCNS_COLOR_RGB888_BLACK,
        SCNS_COLOR_RGB888_RED,
        SCNS_COLOR_RGB888_GREEN,
        SCNS_COLOR_RGB888_BLUE,
        SCNS_COLOR_RGB888_YELLOW,
        SCNS_COLOR_RGB888_CYAN,
        SCNS_COLOR_RGB888_PURPLE,
        SCNS_COLOR_RGB888_WHITE,
    };
    for(int i=0;;i=(i+1)%255)
    {
        //scnsLedRgbSet(SCNS_LED_RGB_L,SCNS_COLOR_RGB888_GREEN);
        //scnsBspLedRgbSetR(SCNS_LED_RGB_L,65535);
        //scnsBspLedRgbSetG(SCNS_LED_RGB_L,65535);
        //scnsBspLedRgbSetB(SCNS_LED_RGB_L,65535);
        //scnsBspLedRgbSetR(SCNS_LED_RGB_R,65535);
        scnsIwdgFeed();
        scnsMenuFresh();
        if(scnsMenuCanPageDisplay(1))
        {
            scnsJoystickDisplay(SCNS_JOYSTICK_L,SCNS_LCD_LAYER_AUTO,(Point){.x=200,.y=0},120);
            scnsJoystickDisplay(SCNS_JOYSTICK_R,SCNS_LCD_LAYER_AUTO,(Point){.x=200,.y=120},120);
        }
        static uint64 t=0;
        if(t<=scnsTimerGetUs())
        {
            t=scnsTimerGetUs()+50*1000;
            static const uint8 txAddr[5]={0X12,0X25,0XFF,0XFF,0XFF};
            scnsJoystickEncode(SCNS_JOYSTICK_L,nrfSendBuf);
            scnsJoystickEncode(SCNS_JOYSTICK_R,nrfSendBuf+6);
            if(SCNS_STATUS_OK!=scnsNrf24L01Send(SCNS_NRF24L01_1,txAddr,nrfSendBuf,(sizeof nrfSendBuf)))
            {
                scnsLedToggleAfter(SCNS_LED_D3,25*1000);
               // scnsLedRgbToggleAfter(SCNS_LED_RGB_L,25*1000,colors,(sizeof colors)/(sizeof colors[0]));
                scnsLedRgbRToggleAfter(SCNS_LED_RGB_L,25*1000,65535);
            }
        }
        //scnsLedRgbSet(SCNS_LED_RGB_L,colors[(scnsTimerGetUs()/1000000)%((sizeof colors)/(sizeof colors[0]))]);
        //scnsLedRgbSet(SCNS_LED_RGB_R,colors[(scnsTimerGetUs()/1000000)%((sizeof colors)/(sizeof colors[0]))]);
    }
}
